import { Component,  Input, OnInit } from '@angular/core';
import {createElement} from "@angular/core/src/view/element";

@Component({
  selector: 'app-table-contrast',
  templateUrl: './table-contrast.component.html',
  styleUrls: ['./table-contrast.component.css']
})
export class TableContrastComponent implements OnInit {
  @Input() companyna:string;
  @Input() stationna:string;
  @Input() unitna:string;
  public select1={
    companys:[{name:'乌江'},{name:'XX'}],
    stations:[{name:'东风'},{name:'洪家渡'}],
    units:[{name:'#1'},{name:'#2'}]
  };
  public parameters=['振动区运行时间占比','超标XX'];
  ths = ['','效率偏差','导叶漏水率','温升XX','冷却XX'];
  thlength=this.ths.length-1;
  data = [['',0,0,0,0]];
  public companyname;
  public stationname;
  public unitname;
  public parametername;

  public selectCompany:any;
  public selectStation:any;
  public selectUnit:any;
  public selectParameter:any;

  companyChange(selectCompany:any){
    this.companyname = selectCompany.name;
  }
  stationChange(selectStation:any){
    this.stationname = selectStation.name;
  }
  unitChange(selectUnit:any){
    this.unitname = selectUnit.name;
  }
  parameterChange(selectParameter:any){
    this.parametername = selectParameter;
    console.log(this.parametername)
  }


  addunit() {
    let data = [];
    data.push(this.companyname + ' ' + this.stationname + ' ' + this.unitname)
    for(let i=1;i<this.ths.length;i++){
      switch (this.ths[i]){
        case '效率偏差':data.push(0);break;        //该参数数值
        case '导叶漏水率':data.push(0);break;
        case '温升XX':data.push(0);break;
        case '冷却XX':data.push(0);break;
        case '振动区运行时间占比':data.push(0);break;
        case '超标XX':data.push(0);break;
      }
    }
    this.data.push(data);
  }
  addparameter(){
    let parametername = this.parametername;
    this.ths.push(parametername);
    console.log(this.ths);
    for(let i=0;i<this.data.length;i++){
      this.data[i].push(0);                     //该参数的数值
    }
  }
  constructor() { }

  ngOnInit() {
    this.data[0][0]=this.companyna+' '+this.stationna+' '+this.unitna;
    this.select1.companys.forEach(company=>{
      if(company.name==this.companyna){
        this.selectCompany=company
      }
    });
    this.select1.stations.forEach(station=>{
      if(station.name==this.stationna){
        this.selectStation=station
      }
    });
    this.select1.units.forEach(unit=>{
      if(unit.name==this.unitna){
        this.selectUnit=unit
      }
    });
    this.companyname=this.selectCompany.name;
    this.stationname= this.selectStation.name;
    this.unitname= this.selectUnit.name;
    this.selectParameter=this.parameters[0];
    this.parametername = this.selectParameter;
  }
  remove(index) {
    this.data.splice(parseInt(index), 1);
  }
  removparameter(index){
    this.ths.splice(parseInt(index),1);
    for(let i=0;i<this.data.length;i++){
      this.data[i].splice(parseInt(index),1);
    }
  }
}
